package avicit.cbb.businessclass.fondsmanage.rest;


import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsDb;
import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsDbV;
import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsServer;
import avicit.cbb.businessclass.fondsmanage.domain.CbbFondsServerV;
import avicit.cbb.businessclass.fondsmanage.service.CbbFondsDbService;
import avicit.cbb.businessclass.fondsmanage.service.api.CbbFondsDbServiceApi;
import avicit.cbb.businessclass.system.dataauth.rest.BaseExtendAuthServiceRest;
import avicit.im.common.CommonTreeNode;
import avicit.platform6.core.dao.Paging;
import avicit.platform6.core.rest.msg.ResponseMsg;
import avicit.platform6.core.jdbc.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
@Api(tags = "CbbFondsDbServiceRest", description = "CbbFondsDbService_Rest")
@RequestMapping("/api/avicit/cbb/businessclass/fondsmanage/rest/CbbFondsDbServiceRest")
public class CbbFondsDbServiceRest {

    private static final Logger LOGGER = LoggerFactory.getLogger(CbbFondsDbServiceRest.class);


    @Resource
    private CbbFondsDbService cbbFondsDbService;


    /**
     * 加载全宗组织部门树
     * @param map
     * @return
     */
    @PostMapping("/getChildsNode")
    @ApiOperation(value = "加载全宗组织部门树")
    public ResponseMsg<List<CommonTreeNode>> getChildsNode(@ApiParam(value = "加载全宗组织部门树", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<CommonTreeNode>> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            String deptId = (String) map.get("deptId");
            String orgId = (String) map.get("orgId");
            List<CommonTreeNode> childsNode = cbbFondsDbService.getChildsNode(id, deptId, orgId);
            responseMsg.setResponseBody(childsNode);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 查询全宗信息
     * @param map
     * @return
     */
    @PostMapping("/loadCbbFondsDb")
    @ApiOperation(value = "查询全宗信息")
    public ResponseMsg<Page<Map<String, Object>>> loadCbbFondsDb(@ApiParam(value = "查询全宗信息", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<Page<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Paging<CbbFondsDbV> page = (Paging<CbbFondsDbV>) map.get("page");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            Page<Map<String, Object>> mapPage = cbbFondsDbService.loadCbbFondsDb(page, parameter);
            responseMsg.setResponseBody(mapPage);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除全宗记录
     * @param map
     * @return
     */
    @PostMapping("/deleteCbbFondsDb")
    @ApiOperation(value = "删除全宗记录")
    public ResponseMsg deleteCbbFondsDb(@ApiParam(value = "删除全宗记录", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String ids = (String) map.get("ids");
            cbbFondsDbService.deleteCbbFondsDb(ids);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据全宗记录ID删除全文服务器记录
     * @param map
     * @return
     */
    @PostMapping("/deleteCbbFondsServerByDbId")
    @ApiOperation(value = "根据全宗记录ID删除全文服务器记录")
    public ResponseMsg deleteCbbFondsServerByDbId(@ApiParam(value = "根据全宗记录ID删除全文服务器记录", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String ids = (String) map.get("ids");
            cbbFondsDbService.deleteCbbFondsServerByDbId(ids);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 查询全文服务器设置信息
     * @param map
     * @return
     */
    @PostMapping("/loadCbbFondsServer")
    @ApiOperation(value = "查询全文服务器设置信息")
    public ResponseMsg<Page<Map<String, Object>>> loadCbbFondsServer(@ApiParam(value = "查询全文服务器设置信息", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<Page<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            Paging<CbbFondsServerV> page = (Paging<CbbFondsServerV>) map.get("page");
            Map<String, Object> parameter = (Map<String, Object>) map.get("parameter");
            Page<Map<String, Object>> maps = cbbFondsDbService.loadCbbFondsServer(page, parameter);
            responseMsg.setResponseBody(maps);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除全文服务器设置信息
     * @param map
     * @return
     */
    @PostMapping("/deleteCbbFondsServer")
    @ApiOperation(value = "删除全文服务器设置信息")
    public ResponseMsg<Page<Map<String, Object>>> deleteCbbFondsServer(@ApiParam(value = "删除全文服务器设置信息", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<Page<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String ids = (String) map.get("ids");
            cbbFondsDbService.deleteCbbFondsServer(ids);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 获取部门编号、名称信息
     * @param map
     * @return
     */
    @PostMapping("/getSysOrgInfo")
    @ApiOperation(value = "获取部门编号、名称信息")
    public ResponseMsg<Map<String, Object>> getSysOrgInfo(@ApiParam(value = "获取部门编号、名称信息", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            Map<String, Object> sysOrgInfo = cbbFondsDbService.getSysOrgInfo(orgId);
            responseMsg.setResponseBody(sysOrgInfo);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据ID获取全宗视图对象
     * @param map
     * @return
     */
    @PostMapping("/getCbbFondsDbV")
    @ApiOperation(value = "根据ID获取全宗视图对象")
    public ResponseMsg<List<Map<String, Object>>> getCbbFondsDbV(@ApiParam(value = "根据ID获取全宗视图对象", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            List<Map<String, Object>> cbbFondsDbV = cbbFondsDbService.getCbbFondsDbV(id);
            responseMsg.setResponseBody(cbbFondsDbV);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据ID获取全文服务器信息设置视图对象
     * @param map
     * @return
     */
    @PostMapping("/getCbbFondsServerV")
    @ApiOperation(value = "根据ID获取全文服务器信息设置视图对象")
    public ResponseMsg<List<Map<String, Object>>> getCbbFondsServerV(@ApiParam(value = "根据ID获取全文服务器信息设置视图对象", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            List<Map<String, Object>> cbbFondsServerV = cbbFondsDbService.getCbbFondsServerV(id);
            responseMsg.setResponseBody(cbbFondsServerV);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 新增全宗管理记录
     * @param map
     * @return
     */
    @PostMapping("/insertCbbFondsDb")
    @ApiOperation(value = "新增全宗管理记录")
    public ResponseMsg insertCbbFondsDb(@ApiParam(value = "新增全宗管理记录", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            CbbFondsDb cbbFondsDb = (CbbFondsDb) map.get("cbbFondsDb");
            cbbFondsDbService.insertCbbFondsDb(cbbFondsDb);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 更新全宗管理记录
     * @param map
     * @return
     */
    @PostMapping("/updateCbbFondsDb")
    @ApiOperation(value = "更新全宗管理记录")
    public ResponseMsg updateCbbFondsDb(@ApiParam(value = "更新全宗管理记录", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            CbbFondsDb cbbFondsDb = (CbbFondsDb) map.get("cbbFondsDb");
            cbbFondsDbService.updateCbbFondsDb(cbbFondsDb);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 添加唯一性校验
     * @param map
     * @return
     */
    @PostMapping("/saveUniqueValidate")
    @ApiOperation(value = "添加唯一性校验")
    public ResponseMsg<Boolean> saveUniqueValidate(@ApiParam(value = "添加唯一性校验", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        try {
            String fullsvrType = (String) map.get("fullsvrType");
            String svrAddress = (String) map.get("svrAddress");
            String svrPublishPath = (String) map.get("svrPublishPath");
            String ftpUser = (String) map.get("ftpUser");
            boolean b = cbbFondsDbService.saveUniqueValidate(fullsvrType, svrAddress, svrPublishPath, ftpUser);
            responseMsg.setResponseBody(b);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 新增全宗管理记录
     * @param map
     * @return
     */
    @PostMapping("/insertCbbFondsServer")
    @ApiOperation(value = "新增全宗管理记录")
    public ResponseMsg insertCbbFondsServer(@ApiParam(value = "新增全宗管理记录", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            CbbFondsServer cbbFondsServer = (CbbFondsServer) map.get("cbbFondsServer");
            cbbFondsDbService.insertCbbFondsServer(cbbFondsServer);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 更新全文服务器记录
     * @param map
     * @return
     */
    @PostMapping("/updateCbbFondsServer")
    @ApiOperation(value = "更新全文服务器记录")
    public ResponseMsg updateCbbFondsServer(@ApiParam(value = "更新全文服务器记录", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            CbbFondsServer cbbFondsServer = (CbbFondsServer) map.get("cbbFondsServer");
            cbbFondsDbService.updateCbbFondsServer(cbbFondsServer);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 编辑唯一性校验
     * @param map
     * @return
     */
    @PostMapping("/editUniqueValidate")
    @ApiOperation(value = "编辑唯一性校验")
    public ResponseMsg<Boolean> editUniqueValidate(@ApiParam(value = "编辑唯一性校验", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<Boolean> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            String fullsvrType = (String) map.get("fullsvrType");
            String svrAddress = (String) map.get("svrAddress");
            String svrPublishPath = (String) map.get("svrPublishPath");
            String ftpUser = (String) map.get("ftpUser");
            boolean b = cbbFondsDbService.editUniqueValidate(id, fullsvrType, svrAddress, svrPublishPath, ftpUser);
            responseMsg.setResponseBody(b);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

}
